<template>
  <div id="app">
    <h2>测试题</h2>
    <SubjectItem
      :number1="list[index].number1"
      :number2="list[index].number2"
      v-for="(item, index) in list"
      :key="item.id"
      @check="checkfn"
    ></SubjectItem>
    <FlagItem
      v-for="(item, index) in flagitem"
      :key="index"
      :flagitem="item"
      :id="index + 1"
    ></FlagItem>
  </div>
</template>

<script>
import SubjectItem from './components/SubjectItem.vue'
import FlagItem from './components/FlagItem.vue'
export default {
  data() {
    return {
      list: [],
      flagitem: []
    }
  },
  components: {
    SubjectItem,
    FlagItem
  },
  created() {
    this.getrandom()
  },
  methods: {
    getrandom() {
      for (let i = 0; i < 5; i++) {
        let number1 = parseInt(Math.random() * 10)
        let number2 = parseInt(Math.random() * 10)
        let obj = {
          number1: number1,
          number2: number2
        }
        this.list.push(obj)
      }
    },
    checkfn(val) {
      if (val === 1) {
        this.flagitem.push({
          name: '回答正确',
          status: 'right'
        })
        console.log('回答正确')
      } else if (val === 2) {
        this.flagitem.push({
          name: '未完成',
          status: 'undo'
        })
        console.log('未完成')
      } else {
        this.flagitem.push({ name: '回答错误', status: 'error' })
        console.log('回答错误')
      }
    }
  }
}
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>
